import { defineStore } from "pinia"
import { ref } from "vue"
import { post, put, del } from "../request"
export const useServerStore = defineStore("server", () => {
    const show = ref(false)
    const data = ref({

        base_name: "",//申请人
        base_deptname: "",//申请人部门
        sericnum: "",//单号
        name: "",//客户名称
        suoname: "",//所属人
        type: "",//类型
        laiyuan: "",//来源
        unitname: "",//客户单位
        tel: "",//联系电话
        mobile: "",//手机
        shi: "",//所在市，
        sheng: "",//所在省
        email: "",//邮箱
        address: "",//地址
        routeline: "",//交通路线
        status: "",//状态
        isstat: "",//是否标星
        isgys: "",//是否供应商
        linkname: "",//联系人
        explain: "",//备注
        htshu: "",//合同数
        moneryz: "",//销售总额
        moneryd: "",//代销总额
        lie: "",//操作列
    })
    const datas = ref({
        ids: "",
        client: "",
        data: "",
        price: "",
        flag: "",
        status: "",
    })
    const mong = ref({
        base_name: "",//申请人
        base_deptname: "",//申请人部门
        sericnum: "",//单号
        sustid: "",//单号
        name: "",//客户名称
        aoolydt: "",//所属人
        money: "",//金额
        adddt: "",//日期
        createname: "",//创建人
        optname: "",//销售人
        state: "",//状态
        explain: "",//备注
        lie: "",//操作列
    })
    const list = ref(
        {

            base_name: '管理员',//申请人
            base_deptname: '开发部',//申请人部门
            sericnum: '',//单号
            num: '',//合同编号
            custid: '',//客户名称
            custname: '',//客户名称
            optname: '',//拥有人
            saleid: '',// 销售机会
            signdt: '', // 签约日期
            money: '', // 合同金额
            startdt: '', // 生效日期
            enddt: '',// 截止日期
            content: '',// 合同内容
            type: '', // 合同类型
            moneys: '',// 待收/付金额
            explain: '',// 说明
            statetext: '',// 状态
            createname: '',// 创建人
            lie: '' // 操作列
        }
    );
    const mony = ref(
        {
            base_name: '管理员',//申请人
            base_deptname: '开发部',//申请人部门
            sericnum: '',//单号
            optname: "",//所属人
            hitd: "",//合同
            num: '',//合同编号
            dt: "",//所属日期
            custid: '',//客户名称
            custname: '',//客户名称
            type: '', // 合同类型
            moneys: '',// 待收/付金额
            ispay: "",//是否付款
            paydt: "",//付款时间
            explain: '',// 说明
            createname: '',// 创建人
            lie: '' // 操作列
        }
    );
    const adddata = async () => {
        let res = post("/client/addcystoModel", data.value)
    }
    const shows = () => {
        show.value = true;
    };
    const showlist = (item) => {
        list.value = { ...item }
    }
    const on_close = () => {
        show.value = false;
    };
    const showload = (item) => {
        console.log(item);
        data.value = { ...item }
    }
    const addmong = async () => {
        // console.log(mong.value);
        let res = await post("/client/addsersModel", mong.value)

    }
    const addmony = async () => {
        // console.log(mong.value);
        let res = await post("/client/addmonyModel", mony.value)
        console.log(res);
        
    }
    const getmony = async () => {
        const res = await post("/client/getmony", mony.value)
        console.log(res);
    }
    const showmony = (item) => {
        mony.value = { ...item }
    }
    const showmong = (item) => {
        mong.value = { ...item }
    }
    const showloads = (item) => {
        console.log(item);
        datas.value = { ...item }
    }

    const edit = (item) => {
        data.value = { ...item, status: "false" }
    }
    const edits = async () => {
        const res = await put("/client/editcystoModel", data.value)
    }
    const editmong = async () => {
        const res = await put("/client/editsersModel", mong.value)
    }

    const deletes = async (id) => {
        const res = await del("/client/delcystoModel", { _id: id })
    }
    const addtong = async () => {
        console.log(1);
        // console.log(list.value);
        const res = await post("/client/addtong", list.value)
        console.log(res);

    }
    return {
        data,
        datas,
        show,
        shows,
        on_close,
        adddata,
        showload,
        showloads,
        edit,
        edits,
        deletes,
        mong,
        addmong,
        showmong,
        editmong,
        list,
        addtong,
        showlist,
        mony,
        getmony,
        showmony,
        addmony
    }
})  